<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //什么时候执行
        //当Promise状态发生变化时，不论如何都会执行，不变化不执行
        new Promise((resolve, reject) => {
            // resolve(123);
            reject('reason');
        }).finally((data) => {
            console.log(data);
        }).catch((err) => {

        })

        //本质：finally本质上是then()的特例
        //上面的代码等价于
        new Promise((resolve, reject) => {
                // resolve(123);
                reject('reason');
            })
            .then((result) => {
                return result;
            }, err => {
                return new Promise((resolve, reject) => {
                    reject(err);
                })

            }).catch((err) => {
                console.log(err);
            })
    </script>
</body>

</html>